//Load maker drop down
$(document).ready(function() {
	$('#wait_1').hide();
	$('#drop_1').change(function(){
	  $('#wait_1').show();
	  $('#result_1').hide();
      $.get("functions.php", {
		func: "drop_1",
		vehicleYear: $('#drop_1').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});
//finish maker drop down
function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}

//Load model drop down
$('#wait_2').hide();
$('#drop_2').change(function () {
    $('#wait_2').show();
    $('#result_2').hide();
    $.get("functions.php", {
        func: "drop_2",
        vehicleYear: $('#drop_1').val(),
        vehicleMaker: $('#drop_2').val()
    }, function (response) {
        $('#result_2').fadeOut();
        setTimeout("finishAjax_modelYear('result_2', '" + escape(response) + "')", 400);
    });
    return false;
});

//finish model drop down
function finishAjax_modelYear(id, response) {
  $('#wait_2').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}

//Load transmission drop down
$('#wait_3').hide();
$('#drop_3').change(function () {
    $('#wait_3').show();
    $('#result_3').hide();
    $.get("functions.php", {
        func: "drop_3",
        vehicleYear: $('#drop_1').val(),
        vehicleMaker: $('#drop_2').val(),
        vehicleModel: $('#drop_3').val()
    }, function (response) {
        $('#result_3').fadeOut();
        setTimeout("finishAjax_transmission('result_3', '" + escape(response) + "')", 400);
    });
    return false;
});

//finish transmission drop down
function finishAjax_transmission(id, response) {
  $('#wait_3').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}


//Load submit button
$(document).ready(function() {
	$('#wait_4').hide();
	$('#drop_4').change(function(){
	  $('#wait_4').show();
	  $('#result_4').hide();
      $.get("functions.php", {
		func: "drop_4",
		vehicleYear: $('#drop_4').val()
      }, function(response){
        $('#result_4').fadeOut();
        setTimeout("finishAjax_button('result_4', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});
//finish maker drop down
function finishAjax_button(id, response) {
  $('#wait_4').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
